home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MACSHELL / MS1 / COMMANDS / PATHCMDS.C < prev    next >
Text File  |  1992-12-02  |  7KB  |  288 lines

  1. /*
  2.  *    MacShell Source File
  3.  *
  4.  *    Copyright (c) 1989, 1990, 1991, 1992  Suick Bay Technologies.  All rights reserved.
  5.  *
  6.  *
  7.  *    RESTRICTIONS ON MacShell program and source code.
  8.  *
  9.  *    Ñ╩MacShell¬ is a product of Suick Bay Technologies and is provided for
  10.  *    restricted use by the owner of the CDROM "Disk to the future II".
  11.  *
  12.  *    Ñ╩No permission is granted for any commercial use without the written
  13.  *    consent of the Suick Bay Technologies.
  14.  *
  15.  *    Ñ╩No permission is granted for any redistribution of any kind use without
  16.  *    the written consent of the Suick Bay Technologies.
  17.  *
  18.  *    Ñ╩Permission is granted to use this for any personal noncommercial use.
  19.  *
  20.  *    Ñ╩You may not distribute source or executable code at all, nor may you 
  21.  *    distribute it with or within a commercial product without the written
  22.  *    consent of the Suick Bay Technologies.  Please send modifications to 
  23.  *    the author for inclusion in updates to the program.  Thanks.
  24.  *
  25.  *
  26.  *    MacShell¬ IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  27.  *    WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  28.  *    PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  29.  *
  30.  *    SUICK BAY TECHNOLOGIES SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  31.  *    INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY MACSHELL
  32.  *    OR ANY PART THEREOF. 
  33.  *
  34.  *    In no event will Suick Bay Technologies be liable for any lost revenue
  35.  *    or profits or other special, indirect and consequential damages, even if
  36.  *    Suick Bay Technologies has been advised of the possibility of such damages.
  37.  *
  38.  *    Suick Bay Technologies can be reached at:
  39.  *    
  40.  *    8768 Cottonwood lane
  41.  *    Maple Grove, MN 55369
  42.  *    Voice: (612) 425-7025
  43.  *    AppleLink: D5233
  44.  *    
  45.  *
  46.  *    No parts of this software may be reproduced or stored in a
  47.  *    retrieval system or transmitted in any form, or any means,
  48.  *    electronic, mechanical, photocopying, recording or otherwise,
  49.  *    without the prior written permission of Suick Bay Technologies.
  50.  *    
  51.  *    Spread the word and not the disk.
  52.  *    
  53.  *    SPK 012290    :    Initial
  54.  */
  55.  
  56. #include    "SystemPub.h"
  57. #include    "Proc.h"
  58. #include    "ShellPub.h"
  59. #include    "Path.h"
  60.  
  61. /********************************************************************
  62.  *    Set working directory dialog
  63.  ********************************************************************/
  64.  
  65. #define FINDDLOG     1010        /*    Set working dir dialog  */
  66. #define FLDRBUTN    11            /*  The "Set" button  */
  67.  
  68. /*******************************************************************/
  69.  
  70. pascal Boolean     folderFilter(p)
  71. ParmBlkPtr         p;
  72. {
  73.     if ((p->fileParam.ioFlAttrib & 0x10) != 0)
  74.         return(false);
  75.         
  76.     return(true);
  77. }
  78.  
  79. /*******************************************************************/
  80.  
  81. pascal int16     getDirHook( item, dPtr )
  82. short            item;
  83. DialogPtr        dPtr;
  84. {
  85. int16     returnItem;
  86.  
  87.     returnItem = item;
  88.     switch( item )
  89.         {
  90.         case -1:
  91.             break;
  92.             
  93.         case FLDRBUTN:
  94.             returnItem = 1;
  95.             break;
  96.         };
  97.  
  98.     return( returnItem );
  99. }
  100.  
  101. /*******************************************************************/
  102.  
  103. static    SFReply setReply;
  104.  
  105. SetDirFolder( WHandle ShellWh )
  106. {
  107. Point            SFGwhere;
  108. SFTypeList        typeList;
  109. ShellWindRec    **MyShell;
  110.  
  111.     SFGwhere.h = 90;
  112.     SFGwhere.v = 90;
  113.     
  114.     SFPGetFile( SFGwhere, "\p", folderFilter, 0, typeList,
  115.                             getDirHook, &setReply, FINDDLOG, nil );
  116.                             
  117.     MyShell = (ShellWindRec **) (**ShellWh).thing;
  118.  
  119.     if( setReply.good );
  120.         {
  121.         SetVol( NULL, setReply.vRefNum );
  122.         
  123.         GetPWDInfo( &(**MyShell).pwdVRefNum,
  124.             &(**MyShell).pwdDirID, &(**MyShell).parDirID );
  125.  
  126.         ResetShellPWD( ShellWh );
  127.         }        
  128. }
  129.  
  130. /*******************************************************************/
  131.  
  132. Boolean            DoCD( int16 ProcToken, WHandle ShellWh, int16 ProcID, 
  133.                     char *string )
  134. {
  135. char            *cp, argument[ 256 ];
  136. pathType        pt;
  137. ShellWindRec    **MyShell;
  138. int16            i, argc;
  139. int32            newDirID = 0;
  140.  
  141.     MyShell = (ShellWindRec **) (**ShellWh).thing;
  142.  
  143.     switch( ProcToken )
  144.         {
  145.         case    PROC_INIT    :
  146.             (**MyShell).Proc[ ProcID ].flags = TRUE;
  147.             break;        
  148.             
  149.         case    PROC_TERM    :
  150.         case    PROC_BREAK    :
  151.             /* Tell the shell that we're done */
  152.             SendOutToken( ShellWh, ProcID, PROC_BREAK );
  153.         
  154.             /* Turn ourself off */
  155.             (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  156.             break;
  157.             
  158.         case    PROC_STDIN    :    
  159.             if( (**MyShell).Proc[ ProcID ].flags )
  160.                 {        
  161.                 (**MyShell).Proc[ ProcID ].flags = FALSE;
  162.                 
  163. #ifdef    DEMO
  164.                 procPrintf( ShellWh, ProcID, 
  165.                     "cd : Demo version, cd is not available\n" );
  166. #else
  167.                 
  168.                 if( (**MyShell).Proc[ ProcID ].argc == 1 )
  169.                     {
  170.                     char    *cp;
  171.                     cp = ShellGetVar( ShellWh, "CDPATH" );
  172.                     strcpy( argument, cp );
  173.                     }
  174.                 else
  175.                     {
  176.                     argc = (**MyShell).Proc[ ProcID ].argc;
  177.                     for( i = 1; i < argc; i++ )
  178.                         {
  179.                         GetArgv( ShellWh, ProcID, i, argument );
  180.                         cp = argument;
  181.                         
  182.                         if( *cp++ == '-' )
  183.                             {
  184.                             while( *cp )
  185.                                 switch( *cp++ )
  186.                                     {
  187.                                     case    'd'    :
  188.                                         SetDirFolder( ShellWh );
  189.                                         goto EndCD;
  190.                                         
  191.                                     case    'i'    :
  192.                                         i++;
  193.                                         GetArgv( ShellWh, ProcID, i, argument );
  194.                                         CtoPstr( argument );
  195.  
  196.                                         if( GoodNum( argument ) )
  197.                                             {
  198.                                             int16    err;
  199.                                             StringToNum( argument, &newDirID );
  200.                                             
  201.                                             if( err = SetWD( (**MyShell).pwdVRefNum, newDirID ) )
  202.                                                 procPrintf( ShellWh, ProcID, 
  203.                                                     "cd : can't set DirID %ld (%d)\n", newDirID, err );
  204.                                             else
  205.                                                 (**MyShell).pwdDirID = newDirID;
  206.                                                 
  207.                                             ResetShellPWD( ShellWh );
  208.                                             }
  209.                                         else
  210.                                             procPrintf( ShellWh, ProcID, 
  211.                                                 "cd : can't set DirID %s\n", argument );
  212.                                         goto EndCD;
  213.                                     }
  214.                             }
  215.                         }
  216.                                                                 
  217.                     GetArgv( ShellWh, ProcID, 1, argument );
  218.                     }
  219.                     
  220.                 ResetShellPWD( ShellWh );
  221.                 pt = SetCurrPath( argument );
  222.                 
  223.                 if( pt == pathIsDir || pt == pathIsVol )
  224.                     GetPWDInfo( &(**MyShell).pwdVRefNum,
  225.                         &(**MyShell).pwdDirID, &(**MyShell).parDirID );
  226.                 else
  227.                     procPrintf( ShellWh, ProcID, "cd : can't set %s (%d)\n", argument, pt );
  228.     
  229.                 ResetShellPWD( ShellWh );
  230.  
  231. EndCD:
  232. #endif
  233.                 /* Tell the shell that we're done */
  234.                 SendOutToken(  ShellWh, ProcID, PROC_BREAK );
  235.                 
  236.                 /* Turn ourself off */
  237.                 (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  238.                 return( FALSE );
  239.                 }
  240.         }
  241. }
  242.  
  243. /*******************************************************************/
  244.  
  245. Boolean            DoPWD( int16 ProcToken, WHandle ShellWh, int16 ProcID,
  246.                     char *string )
  247. {
  248. char            str[ 256 ];
  249. int16            err;
  250. ShellWindRec    **MyShell;
  251.     
  252.     MyShell = (ShellWindRec **) (**ShellWh).thing;
  253.  
  254.     switch( ProcToken )
  255.         {
  256.         case    PROC_INIT    :
  257.             (**MyShell).Proc[ ProcID ].flags = TRUE;
  258.             break;
  259.  
  260.         case    PROC_TERM    :
  261.         case    PROC_BREAK    :
  262.             /* Tell the shell that we're done */
  263.             SendOutToken( ShellWh, ProcID, PROC_BREAK );
  264.         
  265.             /* Turn ourself off */
  266.             (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  267.             break;
  268.             
  269.         case    PROC_STDIN    :
  270.             if( (**MyShell).Proc[ ProcID ].flags )
  271.                 {
  272.                 (**MyShell).Proc[ ProcID ].flags = FALSE;
  273.                 ResetShellPWD( ShellWh );
  274.                 
  275.                 if( (err = GetCurrPath( str )) == noErr )
  276.                     procPrintf( ShellWh, ProcID, "%s\n", str );
  277.                 else
  278.                     FileError( err );
  279.  
  280.                 /* Tell the shell that we're done */
  281.                 SendOutToken(  ShellWh, ProcID, PROC_BREAK );
  282.                 
  283.                 /* Turn ourself off */
  284.                 (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  285.                 return( FALSE );
  286.                 }
  287.         }
  288. }